package com.brozha.ans_sys.utils;

import lombok.Data;

import java.io.Serializable;

/**
 * @author brozha
 * @date 2021/4/4
 */
@Data
public class Result<T> {

    public static final String DEFAULT_SUCCESS_MSG = "操作成功";
    public static final String DEFAULT_FAIL_MSG = "操作失败";

    private int code;
    private String msg;
    private T obj;
    private String token;

    public Result(int code,String msg,T obj){
        this.code = code;
        this.msg = msg;
        this.obj = obj;
    }

    public Result(int code,String msg){
        this.code = code;
        this.msg = msg;
    }

    public Result(int code,String msg,T obj,String token){
        this.code = code;
        this.msg = msg;
        this.obj = obj;
        this.token = token;
    }

    public Result(int code,String msg,String token) {
        this.code = code;
        this.msg = msg;
        this.token = token;
    }

    public static <T> Result successWithToken(String msg,T obj,String token){
        return new Result(ResultCode.SUCCESS,msg,obj,token);
    }

    public static <T> Result successWithToken(String msg,String token){
        return new Result(ResultCode.SUCCESS,msg,token);
    }

    public static <T> Result success(String msg,T obj){
        return new Result(ResultCode.SUCCESS,msg,obj);
    }

    public static <T> Result success(T obj){
        return new Result(ResultCode.SUCCESS,DEFAULT_SUCCESS_MSG,obj);
    }

    public static <T> Result success(String msg){
        return new Result(ResultCode.SUCCESS,msg);
    }



    public static <T> Result success(){
        return new Result(ResultCode.SUCCESS,DEFAULT_SUCCESS_MSG);
    }

    public static <T> Result fail(int code,String msg){
        return new Result(code,msg);
    }

    public static <T> Result fail(int code){
        return new Result(code,DEFAULT_FAIL_MSG);
    }

    public static <T> Result fail(String msg){
        return new Result(ResultCode.FAIL,msg);
    }

    public static <T> Result fail(){
        return new Result(ResultCode.FAIL,DEFAULT_FAIL_MSG);
    }






}
